import edu.wsu.KheperaSimulator.RobotController;

/* LoveBangBang.java
 *
 * Author:	Malcolm Staudacher
 * Date:	Nov 2, 2008
 *
 */

/**
 * This controller makes the robot go towards the light, if the light source is
 * in front of it. The robot will stop in close proximity of the light source.
 */
public class LoveBangBang extends BangBang {

	public LoveBangBang() {
		setWaitTime(5);
	}


	public void doWork() throws Exception {

		int lLight = 0;
		int rLight = 0;

		// get an "average" of the light on each side of the robot
		lLight = ((getLightValue(0) + getLightValue(1) + getLightValue(2)) / 100);
		rLight = ((getLightValue(3) + getLightValue(4) + getLightValue(5)) / 100);

		// turn towards the light
		if (lLight < rLight) {
			turnLeft();
		} else if (lLight > rLight) {
			turnRight();
		} else if ((getDistanceValue(2) < 100 && getDistanceValue(3) < 100)) {
			// if the light is equal on both sides, and there is nothing in
			// front, go straight ahead
			advance();
		}

	}


	public void close() throws Exception {
		// TODO Auto-generated method stub

	}


}
